package io.renren.modules.generator.controller;

import com.baomidou.mybatisplus.mapper.Condition;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.generator.entity.SpecEntity;
import io.renren.modules.generator.service.SpecService;
import io.renren.modules.generator.vo.SpecVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 规格表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-12-11 00:13:08
 */
@RestController
@RequestMapping("generator/spec")
public class SpecController {
    @Autowired
    private SpecService specService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:spec:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = specService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/listForSelect")
    public R listForSelect(){
        return R.ok().put("data", specService.listForSelect());
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:spec:info")
    public R info(@PathVariable("id") Long id){
			SpecEntity spec = specService.selectById(id);

        return R.ok().put("spec", spec);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:spec:save")
    public R save(@RequestBody SpecEntity spec){
			specService.insert(spec);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:spec:update")
    public R update(@RequestBody SpecEntity spec){
			specService.updateById(spec);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:spec:delete")
    public R delete(@RequestBody Long[] ids){
			specService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
